<?
include('header.php');
if(!$is_online){
	redirect('index.php');
	exit;
}

if(isset($_POST['change_pass'])){
	if (!checkPwd($_POST['password'],$_POST['password2'])) {
		$mesaj = '<div class="msg"><div class="error">ERROR: Passwords are wrong or doesn\'t match!</div></div><br>';
	}else{
		$enpass = MD5($passa);
		$db->Query("UPDATE `users` SET `pass`='".$enpass."' WHERE `id`='".$data['id']."'");
		$mesaj = '<div class="msg"><div class="success">Password successfully changed!</div></div><br>';
	}
}

if(isset($_POST['change_email'])){
	$email = $db->EscapeString($_POST['email']);

	if (!isEmail($email)) {
		$mesaj = '<div class="msg"><div class="error">ERROR: Please enter a valid e-mail address!</div></div><br>';
	}else if($db->GetNumRows($db->Query("SELECT id FROM `users` WHERE `email`='".$email."'")) > 0){
		$mesaj = '<div class="msg"><div class="error">ERROR: This e-mail address is already registered!</div></div><br>';
	}else{
		$db->Query("UPDATE `users` SET `email`='".$email."' WHERE `id`='".$data['id']."'");
		$mesaj = '<div class="msg"><div class="success">E-mail address successfully changed!</div></div><br>';
	}
}
?>
<div class="block medium right">
			<div class="top">	
                  <h1>Edit Account Details</h1>
            </div>
			<div class="content"><?=$mesaj?><br />
				<form action="" method="post">
					  <fieldset>
					  
						 <p>
							 <label>Email</label> <br/>
							 <input class="text big" type="email" value="<?=$data['email']?>" name="email"/>
						 </p>
						  <p>
						  	<input type="submit" value="Change Email" name="change_email" />
						  </p>
					  </fieldset>
				</form>	<br>			
				<form action="" method="post">
					  <fieldset>
					 
						 <p>
							 <label>Password</label> <br/>
							 <input class="password" type="password" value="" name="password"/>
						 </p>
						 <p>
							 <label>Repeat Password</label> <br/>
							 <input class="password" type="password" value="" name="password2"/>
						 </p>
						  <p>
						  	<input type="submit" value="Change Password" name="change_pass" />
						  </p>
					  </fieldset>
				</form>			
			</div>
</div>
<?include('footer.php');?>